/**
 * @author Created by qiush on 2017-05-27.
 */

import {IBoxRect} from './IBoxRect';
import {IPoint} from './IPoint';

class BoxRect implements IBoxRect {
  readonly top: number = 0;
  readonly left: number = 0;
  readonly width: number = 0;
  readonly height: number = 0;

  constructor(clientRect: ClientRect) {
    if (clientRect) {
      this.top = clientRect.top;
      this.left = clientRect.left;
      this.width = clientRect.width;
      this.height = clientRect.height;
    }
  }

  isEquals(boxRect: IBoxRect): boolean {
    return this.top === boxRect.top && this.left === boxRect.left &&
      this.width === boxRect.width && this.height === boxRect.height;
  }

  isContains(point: IPoint): boolean {
    return this.left <= point.x && point.x <= (this.left + this.width) &&
      this.top <= point.y && point.y <= (this.top + this.height);
  }
}

export default BoxRect;
